/////////////////////////////////////////////////////////////////////////////
// Original code from libhdfs3. Copyright (c) 2013 - 2014, Pivotal Inc.
// All rights reserved. Author: Zhanwei Wang
/////////////////////////////////////////////////////////////////////////////
//  Modifications by Kumo Inc.
// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <ktest/ktest.h>

#include <kmhdfs/client/lease_renewer.h>
#include <tests/mock/mock_file_system_inter.h>

using namespace Hdfs::Internal;
using namespace testing;

TEST(TestRenewer, Renew) {
    std::shared_ptr<MockFileSystemInter> filesystem(new MockFileSystemInter());
    LeaseRenewerImpl renewer;
    renewer.setInterval(1000);
    EXPECT_CALL(*filesystem, getClientName()).Times(2).WillRepeatedly(Return("MockFS"));
    EXPECT_CALL(*filesystem, registerOpenedOutputStream()).Times(1);
    EXPECT_CALL(*filesystem, unregisterOpenedOutputStream()).Times(1).WillOnce(Return(true));
    EXPECT_CALL(*filesystem, renewLease()).Times(AtLeast(1)).WillRepeatedly(Return(true));
    renewer.StartRenew(filesystem);
    sleep_for(seconds(2));
    renewer.StopRenew(filesystem);
}
